package com.hnxxxy.sysmgr.controller;

import com.github.pagehelper.PageHelper;
import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import com.hnxxxy.common.annotation.LogAnno;
import com.hnxxxy.common.tools.Help;
import com.hnxxxy.common.tools.TableObj;
import com.hnxxxy.sysmgr.pojo.Dict;
import com.hnxxxy.sysmgr.service.SysDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/sys")
@RestController
@Slf4j
public class SysDictionaryController {

    @Autowired
    SysDictionaryService sysDictionaryService;

    @RequestMapping("/f/sysDictionary")
    @LogAnno(description = "查询字典信息")
    public TableObj findAlSysDictionary(TableObj tableObj, Dict dict){
        PageHelper.startPage(tableObj.getCurr(), tableObj.getNums());
        List<Dict> list = sysDictionaryService.findAlSysDictionary(dict);
        return Help.getPageTableRtn(tableObj,list);
    }

    @RequestMapping("/d/sysDictionary")
    @LogAnno(description = "字典信息删除",descriptiontype = "deleteSysDictionary")
    public AjaxRtnEntity deleteSysDictionary(@RequestParam("ids[]") Integer[] ids){
        AjaxRtnEntity ajaxRtnEntity=new AjaxRtnEntity(sysDictionaryService.deleteSysDictionary(ids),"删除成功",null);
        return ajaxRtnEntity;
    }

    @RequestMapping("/u/sysDictionary")
    @LogAnno(description = "字典信息修改",descriptiontype = "updateSysDictionary")
    public AjaxRtnEntity updateSysDictionary(@RequestBody Dict dict){
        AjaxRtnEntity ajaxRtnEntity=new AjaxRtnEntity(sysDictionaryService.updateSysDictionary(dict),"修改成功",null);
        return ajaxRtnEntity;
    }

    @RequestMapping("/i/sysDictionary")
    @LogAnno(description = "字典信息添加",descriptiontype = "insertSysDictionary")
    public AjaxRtnEntity insertSysDictionary(@RequestBody Dict dict){
        AjaxRtnEntity ajaxRtnEntity=new AjaxRtnEntity(sysDictionaryService.insertSysDictionary(dict),"添加成功",null);
        return ajaxRtnEntity;
    }

}
